package com.example.yangjintingtest.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class MyMVCConfig implements WebMvcConfigurer {
    @Autowired
    private MyInterceptor myInterceptor;

    // 添加拦截器管理
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器
        registry.addInterceptor(myInterceptor)
                .addPathPatterns("/**")
                //不拦截登录、上传下载文件端口
                .excludePathPatterns("/article/**", "/ueUploadController/**", "/toRegister", "/admin/toLogin", "/admin/login",
                        "/delete/**", "/update/**", "/get/**", "/toLogin", "/login", "/logout", "/toUpload", "/uploadFile",
                        "/download", "/toDownload", "/static/**", "/register")
                .excludePathPatterns("/login.html");
    }


//    @Override
//    public void addInterceptors (InterceptorRegistry registry) {
//        registry.addInterceptor (myInterceptor)
//                .addPathPatterns ("/")
//// 不拦截登录，上传下载文件接口
//                .excludePathPatterns ("/toLogin", "/login", "/logout","/toUpload", "/uploadFile","/download","/toDownload","/static/")
//                .excludePathPatterns("/login.html");
//    }
    @Override
    public void addResourceHandlers (ResourceHandlerRegistry registry) {
// 放开 resources/static 下的所有资源拦截
        registry.addResourceHandler ("/static/**")
                .addResourceLocations ("classpath:/static/");
    }
}
